home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / snip9503 / nwlinnam.c < prev    next >
C/C++ Source or Header  |  1995-03-14  |  3KB  |  119 lines

  1. /*
  2. **  NWLINNAME.C - Novell Netware: getNwLoginName
  3. **  This should work for Advanced NetWare (2.x) -> NetWare386 3.x & 4.x
  4. **
  5. **  Written by david nugent, public domain
  6. */
  7.  
  8. /* #define TEST */            /* Uncomment to compile test main()       */
  9.  
  10. #include <string.h>
  11. #include <process.h>
  12. #include <dos.h>
  13. #include <errno.h>
  14.  
  15. #define addrOffset(val)     (unsigned short)(((long)(val)) & 0xfff)
  16.     /* Invoke Novell Netware API.  */
  17. #define callNetware(func, reqbuf, repbuf, inregs, segregs) \
  18.     { \
  19.         (inregs)->h.ah = (func); \
  20.         (inregs)->x.si = addrOffset(reqbuf); \
  21.         (inregs)->x.di = addrOffset(repbuf); \
  22.         intdosx(inregs, inregs, segregs); \
  23.     }
  24.  
  25. #if defined(_MSC_VER) || defined(_QC) || defined(__WATCOM__)
  26.     #pragma pack(1)
  27. #elif defined(__ZTC__)
  28.     #pragma ZTC align 1
  29. #elif defined(__TURBOC__) && (__TURBOC__ > 0x202)
  30.     #pragma option -a-
  31. #endif
  32.  
  33. /*
  34. **  Get Connection Information E3(16)
  35. */
  36.  
  37. struct _conninfo
  38. {
  39.     unsigned short len;
  40.     unsigned char func;
  41.     unsigned char cno;
  42. };
  43.  
  44. struct _connrep
  45. {
  46.     unsigned short len;
  47.     unsigned long objectID;
  48.     unsigned short objecttype;
  49.     char objectname[48];
  50.     unsigned char logintime[7];
  51.     unsigned char reserved[39];
  52. };
  53.  
  54. #if defined(_MSC_VER) || defined(_QC) || defined(__WATCOM__)
  55.     #pragma pack()
  56. #elif defined(__ZTC__)
  57.     #pragma ZTC align 2
  58. #elif defined(__TURBOC__) && (__TURBOC__ > 0x202)
  59.     #pragma option -a
  60. #endif
  61.  
  62. int getNwLoginName (char * namebuf)
  63. {
  64.       union REGS r;
  65.  
  66.       r.x.ax = 0xDC00;    /* Get Connection Number */
  67.       intdos(&r, &r);
  68.  
  69.       /*
  70.       ** If the connection number is in range 1-100 (ie. valid),
  71.       ** get Connection Information and retrieve the user name.
  72.       */
  73.  
  74.       if (r.h.al <= 0 ||  r.h.al > 100)
  75.             return errno = EINVAL;
  76.  
  77.       else
  78.       {
  79.             struct SREGS s;
  80.             static struct _connrep connrep;
  81.             static struct _conninfo conninfo;
  82.  
  83.             conninfo.len = sizeof(conninfo) - sizeof(conninfo.len);
  84.             conninfo.func = 0x16;   /* Get connection information */
  85.             conninfo.cno = r.h.al;
  86.             connrep.len = sizeof(connrep) - sizeof(connrep.len);
  87.             segread(&s);
  88.             s.es = s.ds;    /* ds:si=request buffer, es:di=reply buffer */
  89.  
  90.             /* login info */
  91.  
  92.             callNetware(0xE3, &conninfo, &connrep, &r, &s);
  93.             if (r.h.al == 0)
  94.             {
  95.                   strcpy (namebuf, connrep.objectname);
  96.                   return 0;
  97.             }
  98.             return r.h.al;
  99.       }
  100. }
  101.  
  102. #if defined(TEST)
  103.  
  104. #include <stdio.h>
  105.  
  106. int
  107. main()
  108. {
  109.       char loginname[48];
  110.       int rc = getNwLoginName (loginname);
  111.  
  112.       if (rc == 0)
  113.             printf ("Your login name is '%s'\n", loginname);
  114.       else  printf ("Error %d calling Netware, %s\n", rc, strerror(errno));
  115.       return 0;
  116. }
  117.  
  118. #endif
  119.